#Region " Imports "

Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Configuration
Imports System.Configuration.ConnectionStringsSection
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web
Imports System.Web.Configuration
Imports System.Web.Security
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Globalization
Imports WebBase
Imports BA.DAL

#End Region

Partial Class Install_DBUpgrade
    Inherits InstallerBase

#Region " Enums, Memebers and Properties "

	Private SQLscripts As String() = New String() {"UpgradeDatabaseTo_1_5.sql", "UpgradeDatabaseDataTo_1_5.sql"}
	Private DBVersion As Decimal = 1.5

#End Region

#Region " Page Events "

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Me.Page.IsPostBack = False Then
            LoadSettings(Me.uxConnectionStringTextBox)
        End If

    End Sub

#End Region

#Region " Save Data "

#End Region

#Region " Load Data "

#End Region

#Region " Form Controls Events "

    Protected Sub uxUpgradeDatabaseButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles uxUpgradeDatabaseButton.Click
        Dim configuration As Configuration = WebConfigurationManager.OpenWebConfiguration("~")
        Dim AppSettingsSection As AppSettingsSection = CType(configuration.GetSection("appSettings"), AppSettingsSection)

        If ConnectionSuccess() Then

            If Not IsDBBuilt() Then
                Response.Redirect("DBInstall.aspx")
            End If

            If IsDBCurrent(DBVersion) Then

                DisplayMessage(Resources.Resource.DBIsLatestVersion.ToString.Trim, True, Me.uxStatusLabel)

                System.Threading.Thread.Sleep(5000)

                Response.Redirect("../default.aspx")
            Else
                DisplayMessage(Resources.Resource.DBInstallationStart.ToString.Trim, True, Me.uxStatusLabel)

                If ExecuteDatabaseScripts(SQLscripts) Then
                    DisplayMessage(Resources.Resource.DBInstallationComplete.ToString.Trim, True, Me.uxStatusLabel)

                    AppSettingsSection.Settings("AppInstalled").Value() = "True"
                    configuration.Save()

                    System.Threading.Thread.Sleep(5000)

                    Response.Redirect("../default.aspx")
                Else
                    DisplayMessage(Resources.Resource.DBInstallationFailed.ToString.Trim, False, Me.uxStatusLabel)
                End If
            End If

        Else
            DisplayMessage(Resources.Resource.DBConnectionFailed.ToString.Trim, False, Me.uxStatusLabel)
        End If

    End Sub

    Protected Sub uxTestConnectionButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles uxTestConnectionButton.Click

        If ConnectionSuccess() Then
            DisplayMessage(Resources.Resource.DBConnectionSuccessful.ToString.Trim, True, Me.uxStatusLabel)
        Else
            DisplayMessage(Resources.Resource.DBConnectionFailed.ToString.Trim, False, Me.uxStatusLabel)
        End If

    End Sub

#End Region

#Region " Helpers and Methods "

#End Region

End Class
